<template>
  <div>
    <van-swipe :autoplay="3000">
      <van-swipe-item v-for="(image, index) in images" :key="index">
        <img :src="image.pic" :class="'swp_img'" />
      </van-swipe-item>
    </van-swipe>
    <div class="rec_list">
      <div class="list">
        <p class="list_p1">推荐歌单</p>
        <p class="list_p2" @click="showmorelist">
          查看更多
        </p>
      </div>
      <ul class="list_box">
        <li
          v-for="(el, idx) in partList"
          :key="idx"
          @click="pushSongList(el.id)"
        >
          <div class="listimg_box">
            <img :src="el.picUrl" />
            <div class="playCount">
              <div class="playCount_img">
                <img src="../../assets/erji.png" />
              </div>
              <div>{{ (el.playCount / 10000).toFixed(1) }}万</div>
            </div>
          </div>
          <div class="list_name">
            {{ el.name }}
          </div>
        </li>
      </ul>
    </div>
    <div class="newsong_box">
      <div class="ns">
        <p>最新音乐</p>
      </div>
      <ul>
        <!-- 将id_list(id 集合) 与歌曲 idx(下标) 存至vuex，方便后续上下首切换 -->
        <song
          v-for="(song, idx) in newSongs"
          :key="song.id"
          :song_data="{
            song_name: song.name,
            song_artists: song.song.artists,
            song_album: song.song.album.name,
            song_exclusive: song.song.exclusive,
            id: song.id,
          }"
          :id_list="id_lis"
          :idx="idx"
        ></song>
      </ul>
    </div>
  </div>
</template>

<script>
import { get_banner, get_songlist, get_newsong } from "../../api/recommend";
import song from "../../components/song";
export default {
  data() {
    return {
      images: [],
      songList: [],
      newSongs: [],
    };
  },
  components: {
    song,
  },
  created() {
    get_banner().then((res) => {
      this.images = res.data.banners;
    });
    get_songlist().then((res) => {
      this.songList = res.data.result;
      // console.log(res.data.result);
    });
    get_newsong().then((res) => {
      this.newSongs = res.data.result;
    });
  },
  computed: {
    //切割歌单数组，取前6个
    partList() {
      return this.songList.slice(0, 6);
    },
    id_lis() {
      return this.newSongs.map((el) => el.id);
    },
  },
  methods: {
    pushSongList(listId) {
      this.$router.push({
        path: "/songlist",
        query: {
          id: listId,
        },
      });
    },
    showmorelist() {
      this.$router.push({ name: "Morelist" });
    },
  },
};
</script>

<style lang="scss" scoped>
.swp_img {
  width: 100vw;
  height: 38.88%;
}
.rec_list {
  .list {
    // height: 20px;
    display: flex;
    justify-content: space-between;
    .list_p1 {
      border-left: 2px solid #d43c33;
      padding: 0 5px;
      font-weight: bold;
    }
    .list_p2 {
      font-size: 12px;
      height: 20px;
      line-height: 20px;
      padding: 2px 5px;
      border: 1px solid #ccc;
      border-radius: 10px;
    }
  }
  .list_box {
    width: 100%;
    overflow: auto;
    white-space: nowrap;
    li {
      display: inline-block;
      width: 33%;
      height: 33%;
      margin-right: 10px;
      overflow: hidden;
      white-space: pre-wrap;
      vertical-align: top;
      .listimg_box {
        position: relative;
        img {
          border-radius: 10px;
          width: 100%;
          height: 100%;
        }
        .playCount {
          position: absolute;
          top: 0;
          right: 5px;
          display: flex;
          color: white;
          font-size: 12px;
          .playCount_img {
            width: 12px;
            height: 12px;
            padding: 1px 5px 0;
            vertical-align: baseline;
          }
          img {
            width: 100%;
            height: 100%;
          }
        }
      }
      .list_name {
        width: 100%;
        font-size: 13px;
      }
    }
  }
}
.newsong_box {
  .ns {
    text-align: left;
    border-left: 2px solid #d43c33;
    padding: 0 5px;
    font-weight: bold;
  }
  ul {
    width: 100%;
    overflow: hidden;
  }
}
</style>
